<?php

use Drupal\distribution\Entity\DistributionApply;
use Drupal\distribution\Entity\Distribution;

function distribution_apply_edit(DistributionApply $distributionApply) {
  module_load_include('inc', 'distribution', 'distribution.forms');
  return drupal_get_form('distribution_apply_form', $distributionApply, 'edit');
}

function distribution_edit($user) {
  module_load_include('inc', 'distribution', 'distribution.forms');
  $ds = entity_load('distribution', FALSE, ['uid' => $user->uid,]);
  if (!empty($ds)) {
    $distribution = reset($ds);
  }
  else {
    $distribution = new Distribution();
    $distribution->uid = $user->uid;
    $distribution->pid = 0;
    $distribution->tid = 0;
    $distribution->save();
  }
  return drupal_get_form('distribution_distribution_entity_form', $distribution, 'edit');
}
